export const baseURL = "http://192.168.100.174:8081";

const request = (url, method, options = {}, data = {}) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseURL + url,
      method,
      data,
      header: {
        token: wx.getStorageSync('token')
      },
      ...options,
      success: res => {
        // console.log(res, "请求结果");
        resolve(res);
      },
      fail: err => {
        wx.showToast({
          title: '服务错误',
          icon: "none"
        })
        reject();
      }
    })
  })
}
const get = (url, options = {}) => {
  return request(url, "GET", options)
}
const post = (url, data = {}, options = {}) => {
  return request(url, "POST", options, data)
}

export default {
  get,
  post,
  request
}